import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();

async function main() {
  // 创建一个系统用户
  const systemUser = await prisma.user.upsert({
    where: { username: 'system' },
    update: {},
    create: {
      username: 'system',
      password: 'system',
      name: '系统用户',
    },
  });

  // 创建官方行程
  const officialTrips = [
    {
      title: '北京3日游',
      description: '探索中国首都的历史文化',
      startDate: new Date('2024-04-01'),
      endDate: new Date('2024-04-03'),
      isOfficial: true,
      isPublic: true,
      userId: systemUser.id,
      activities: [
        {
          title: '游览故宫',
          description: '参观中国最大的古代宫殿建筑群',
          date: new Date('2024-04-01'),
          metadata: { duration: '4小时' },
        },
        // ... 其他活动
      ],
    },
    // ... 其他行程
  ];

  for (const tripData of officialTrips) {
    const { activities, ...trip } = tripData;
    const createdTrip = await prisma.trip.create({
      data: {
        ...trip,
        activities: {
          create: activities,
        },
      },
    });
    console.log(`Created trip: ${createdTrip.title}`);
  }
}

main()
  .catch((e) => {
    console.error(e);
    process.exit(1);
  })
  .finally(async () => {
    await prisma.$disconnect();
  }); 